﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Model.Common;

namespace Model.Catalog
{
    public class Order
    {
        public Order()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        //-------------------------------------------------------//

        //-------------------------------------------LOCATIONS-----------------------------------------------//
        //Get All Locations
        public static DataTable GetAllLocations()
        {
            try
            {
                return DataAccess.GetData(null, null, "GetAllLocations");
            }
            catch
            {
                return null;
            }
        }

        //------------------------------------------------------------------------------------------//
        //Get Cost by Location Id
        public static DataTable GetLocationByLocationId(string LocationId)
        {
            try
            {
                string[] paramName = { "@LocationId" };
                object[] paramValue = { LocationId };
                return DataAccess.GetData(paramName, paramValue, "GetLocationByLocationId");
            }
            catch
            {
                return null;
            }
        }




        //-------------------------------------------MESSAGES-----------------------------------------------//
        //Get All Messages
        public static DataTable GetAllMessages()
        {
            try
            {
                return DataAccess.GetData(null, null, "GetAllMessages");
            }
            catch
            {
                return null;
            }
        }

        //------------------------------------------------------------------------------------------//
        //Get Message by MessageId
        public static DataTable GetMessageByMessageId(string MessageId)
        {
            try
            {
                string[] paramName = { "@MessageId" };
                object[] paramValue = { MessageId };
                return DataAccess.GetData(paramName, paramValue, "GetMessageByMessageId");
            }
            catch
            {
                return null;
            }
        }




        //------------------------------------------------------------------------------------------//
        //Get Messages by CategoryId
        public static DataTable GetMessagesByCategoryId(string CategoryId)
        {
            try
            {
                string[] paramName = { "@CategoryId" };
                object[] paramValue = { CategoryId };
                return DataAccess.GetData(paramName, paramValue, "GetMessagesCategoryId");
            }
            catch
            {
                return null;
            }
        }


        //--------------------------------------------------------------------------------------------//
        //Add new Order
        public static int AddNewOrder(string Username, string Time, string Name, string Address,string LocationId, string Email,string Sex,string Phone,string MessageContent,string CardNumber)
        {
            string[] paramName = { "@Username", "@Time", "@Name", "@Address", "@LocationId", "@Email", "@Sex", "@Phone", "@MessageContent", "@CardNumber" };
            object[] paramValue = { Username, Time,Name,Address,LocationId,Email,Sex,Phone,MessageContent,CardNumber};
            try
            {
                return DataAccess.InsertUpdate(paramName, paramValue, "InsertNewOrder");
            }
            catch
            {
                return 0;
            }
        }



        //--------------------------------------------------------------------------------------------//
        //Add new a Order detail
        public static int AddNewAOrderDetail(int OrderId, string ProductId, int Quantity, decimal Price)
        {
            string[] paramName = { "@OrderId", "@ProductId", "@Quantity", "@price"};
            object[] paramValue = { OrderId,ProductId,Quantity,Price };
            try
            {
                return DataAccess.InsertUpdate(paramName, paramValue, "InsertOrderDetails");
            }
            catch
            {
                return 0;
            }
        }


        //------------------------------------------------------------------------------------------//
        //Get OrderId Lastest By UserName
        public static DataTable GetOrderIdLastestByUserName(string Username)
        {
            try
            {
                string[] paramName = { "@Username" };
                object[] paramValue = { Username };
                return DataAccess.GetData(paramName, paramValue, "GetOrderIdLastestByUserName");
            }
            catch
            {
                return null;
            }
        }


    }
}
